﻿using System;
using System.Drawing;

namespace Oscilloscope.ChannelBuffer
{
	// Token: 0x0200001C RID: 28
	internal class AnalogChannelBufferDataIterator : IChannelBufferDataIterator
	{
		// Token: 0x0600010C RID: 268 RVA: 0x00008A8C File Offset: 0x00006C8C
		public void Initialize(ChannelBufferData[] dataBuffer, int dataBufferValidCount, double dataBufferStartTime, double timeInterval, int bitIndex)
		{
			this.iteratorNextIndex = 0;
			this.iteratorNextTime = dataBufferStartTime;
			this.iteratorTimeInterval = timeInterval;
			this.dataBufferValidCount = dataBufferValidCount;
			this.dataBuffer = dataBuffer;
			this.pointCountOfSameXloc = 0;
			this.xLoc = null;
			this.pMin = null;
			this.pMinIndex = 0;
			this.pMax = null;
			this.pMaxIndex = 0;
		}

		// Token: 0x0600010D RID: 269 RVA: 0x00008AF8 File Offset: 0x00006CF8
		public bool Next(ref double value, ref double time)
		{
			while (this.iteratorNextIndex < this.dataBufferValidCount)
			{
				if (this.dataBuffer[this.iteratorNextIndex].IsValid)
				{
					value = this.dataBuffer[this.iteratorNextIndex].Data;
					time = this.iteratorNextTime;
					this.iteratorNextIndex++;
					this.iteratorNextTime += this.iteratorTimeInterval;
					return true;
				}
				this.iteratorNextIndex++;
				this.iteratorNextTime += this.iteratorTimeInterval;
			}
			return false;
		}

		// Token: 0x0600010E RID: 270 RVA: 0x00008B98 File Offset: 0x00006D98
		public bool PeekNext(ref double value, ref double time)
		{
			double num = this.iteratorNextTime;
			for (int i = this.iteratorNextIndex; i < this.dataBufferValidCount; i++)
			{
				if (this.dataBuffer[i].IsValid)
				{
					value = this.dataBuffer[i].Data;
					time = num;
					return true;
				}
				num += this.iteratorTimeInterval;
			}
			return false;
		}

		// Token: 0x0600010F RID: 271 RVA: 0x00008BF8 File Offset: 0x00006DF8
		public PointF[] SetNewPoint(float x, float y)
		{
			if (this.xLoc != (int)x)
			{
				PointF[] result = null;
				if (this.pointCountOfSameXloc > 0)
				{
					if (this.pMinIndex == this.pMaxIndex)
					{
						result = new PointF[]
						{
							new PointF(this.pMin.Value.X, this.pMin.Value.Y)
						};
					}
					else if (this.pMinIndex < this.pMaxIndex)
					{
						result = new PointF[]
						{
							new PointF(this.pMin.Value.X, this.pMin.Value.Y),
							new PointF(this.pMax.Value.X, this.pMax.Value.Y)
						};
					}
					else
					{
						result = new PointF[]
						{
							new PointF(this.pMax.Value.X, this.pMax.Value.Y),
							new PointF(this.pMin.Value.X, this.pMin.Value.Y)
						};
					}
				}
				this.pointCountOfSameXloc = 0;
				this.xLoc = new int?((int)x);
				this.pMin = new PointF?(new PointF(x, y));
				this.pMinIndex = this.pointCountOfSameXloc;
				this.pMax = new PointF?(new PointF(x, y));
				this.pMaxIndex = this.pointCountOfSameXloc;
				this.pointCountOfSameXloc++;
				return result;
			}
			if (y > this.pMax.Value.Y)
			{
				this.pMax = new PointF?(new PointF(x, y));
				this.pMaxIndex = this.pointCountOfSameXloc;
			}
			if (y < this.pMin.Value.Y)
			{
				this.pMin = new PointF?(new PointF(x, y));
				this.pMinIndex = this.pointCountOfSameXloc;
			}
			this.pointCountOfSameXloc++;
			return null;
		}

		// Token: 0x06000110 RID: 272 RVA: 0x00008E78 File Offset: 0x00007078
		public PointF[] GetPoint()
		{
			PointF[] result = null;
			if (this.pointCountOfSameXloc > 0)
			{
				if (this.pMinIndex == this.pMaxIndex)
				{
					result = new PointF[]
					{
						new PointF(this.pMin.Value.X, this.pMin.Value.Y)
					};
				}
				else if (this.pMinIndex < this.pMaxIndex)
				{
					result = new PointF[]
					{
						new PointF(this.pMin.Value.X, this.pMin.Value.Y),
						new PointF(this.pMax.Value.X, this.pMax.Value.Y)
					};
				}
				else
				{
					result = new PointF[]
					{
						new PointF(this.pMax.Value.X, this.pMax.Value.Y),
						new PointF(this.pMin.Value.X, this.pMin.Value.Y)
					};
				}
			}
			this.pointCountOfSameXloc = 0;
			this.xLoc = null;
			this.pMin = null;
			this.pMinIndex = 0;
			this.pMax = null;
			this.pMaxIndex = 0;
			return result;
		}

		// Token: 0x04000071 RID: 113
		private int iteratorNextIndex;

		// Token: 0x04000072 RID: 114
		private double iteratorNextTime;

		// Token: 0x04000073 RID: 115
		private double iteratorTimeInterval;

		// Token: 0x04000074 RID: 116
		private int dataBufferValidCount;

		// Token: 0x04000075 RID: 117
		private ChannelBufferData[] dataBuffer;

		// Token: 0x04000076 RID: 118
		private PointF? pMin = null;

		// Token: 0x04000077 RID: 119
		private PointF? pMax = null;

		// Token: 0x04000078 RID: 120
		private int pMinIndex;

		// Token: 0x04000079 RID: 121
		private int pMaxIndex;

		// Token: 0x0400007A RID: 122
		private int pointCountOfSameXloc;

		// Token: 0x0400007B RID: 123
		private int? xLoc = null;
	}
}
